package com.state.pattern;

import com.state.pattern.state.*;
import lombok.Getter;

/**
 * @author chenchen
 * @description 抽奖活动
 * @date 2023/11/8 17:12
 */
public class RaffleActivity {

    // state 表示活动当前的状态，是变化
    private State state;

    // 奖品数量
    @Getter
    int count = 0;

    State noRafflleState = new NoRaffleState(this);
    State canRaffleState = new CanRaffleState(this);
    State dispenseState =   new DispenseState(this);
    State dispensOutState = new DispenseOutState(this);

    //1. 初始化当前的状态
    //2. 初始化奖品的数量
    public RaffleActivity(int count) {
        this.state = noRafflleState;
        this.count = count;
    }

    /**
     * @description 扣分, 调用当前状态的 deductMoney
     * @author chenchen
     * @date 2023/11/8 17:25
     * @param
     * @return void
     */
    public void deductMoney(){
        state.deductMoney();
    }

    /**
     * @description 抽奖
     * @author chenchen
     * @date 2023/11/8 17:26
     * @param
     * @return void
     */
    public void raffle(){
        // 如果当前的状态是抽奖成功
        if(state.raffle()){
            //领取奖品
            state.dispensePrize();
        }
    }

    public void setState(State state) {
        this.state = state;
    }

    public State getState(StateEnum stateEnum) {
        if (stateEnum.equals(StateEnum.NoRaffle)) {
            return noRafflleState;
        } else if (stateEnum.equals(StateEnum.CanRaffle)) {
            return canRaffleState;
        } else if (stateEnum.equals(StateEnum.Dispense)) {
            return dispenseState;
        } else {
            return dispensOutState;
        }
    }
}
